home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 297 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: Randal Parsons <Randal.Parsons@btal.com.au>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Cleaning auto_ptr copy semantics.
  5. Date: 6 Feb 1996 15:41:05 GMT
  6. Organization: Bankers Trust Australia Limited.
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <3116BE3B.1B73@btal.com.au>
  9. References: <01BAF15D.08B8EEE0@dino.int.com>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset="us-ascii"
  13. Content-Transfer-Encoding: 7bit
  14. X-Nntp-Posting-Host: aupozx666.btal.com.au
  15. X-Mailer: Mozilla 2.0b6a (WinNT; I)
  16. X-Lines: 39
  17. Content-Length: 1390
  18. Originator: clamage@taumet
  19.  
  20. Eugene Lazutkin wrote:
  21.  
  22. > I didn't find standard equal-operators:
  23.  
  24. > template<class T>
  25. > bool            operator== ( const auto_ptr<T>& l, const T* r )
  26. >                         { return l.get()==r; }
  27.  
  28. > template<class T>
  29. > bool            operator== ( const T* l, const auto_ptr<T>& r )
  30. >                         { return l==r.get(); }
  31.  
  32. > template<class T>
  33. > bool            operator== ( const auto_ptr<T>& l, const auto_ptr<T>& r )
  34. >                         { return l.get()==r.get(); }
  35.  
  36. > template<class T>
  37. > bool            operator!= ( const auto_ptr<T>& l, const T* r )
  38. >                         { return l.get()!=r; }
  39.  
  40. > template<class T>
  41. > bool            operator!= ( const T* l, const auto_ptr<T>& r )
  42. >                         { return l!=r.get(); }
  43.  
  44. > template<class T>
  45. > bool            operator!= ( const auto_ptr<T>& l, const auto_ptr<T>& r )
  46. >                         { return l.get()!=r.get(); }
  47.  
  48. > It's pretty convinient.  It's good if you are going to create a STL
  49. > container of auto_ptr's.  In this case you can use STL's algorithms.
  50. > Otherwise each programmer should implement this functions manually.
  51.  
  52.  
  53. I agree. I'd like to treat an auto_ptr similarly to a normal pointer. 
  54. This means that operator== and operator!= need to be defined. I'd 
  55. also like to be able to test if its null or not - using operator!() 
  56. and operator int().
  57.  
  58. Randal Parsons.
  59.  
  60. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  61.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  62.   summarized in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  63. ]
  64.